 <?php
  use yii\helpers\Html;
  use yii\helpers\Url;
  use yii\bootstrap\ActiveForm;
  use yii\widgets\LinkPager;

  $this->title = 'create';
 ?>
  <style>
    ul,li{margin:0;padding:0;list-style: none;}
    .search_box{display:none;}
    .search_box .zhezhao{position:fixed;top:0;left:0;right:0;bottom:0;background:#000;opacity:0.6;}
    .search_box .search_form{position:absolute;top:10%;width:60%;background:#FFF;left:20%;}
    .search_box .search_form .form-group{margin-right: 0;margin-left:0;}
    .searchsex_box{overflow:hidden;}
    .searchsex_box>span{float:left;margin-top:10px;font-weight:700;}
    .searchsex_box .radio{float:left;margin-left:50px;}
    .search_form .box-footer{text-align:center;}
    .search_form .box-footer button{width:200px;}
    .sign_btn{float:right;}
    .info_box{display:none;}
    .info_box .zhezhao{position:fixed;top:0;left:0;right:0;bottom:0;background:#000;opacity:.6;}
    .infos{z-index:1000;width:40%;text-align:center;padding:10px 0;line-height:30px;border-radius:3px;background:#3c8dbc;color:#fff;font-size:16px;position:fixed;top:35%;right:20%;}
    .infos li{padding:0 30px;line-height:40px;text-align:left;overflow: hidden;}
    .infos li .lf{float: left;}
    .infos li .rt{float: right;}
  </style>

          <div class="box">
            <div class="box-header">
              <h3 class="box-title">订单列表</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <button type="button" class="btn btn-primary search_btn">搜索</button>
              <button type="button" class="btn btn-primary sign_btn">录入用户</button>
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>barcode</th>
                  <th>姓名</th>
                  <th>性别</th>
                  <th>电话</th>
                  <th>检测时间</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($model as $val) :?>
                <tr>
                  <td class="barcode"><?= $val->barcode ?></td>
                  <td><?= $val->name ?></td>
                  <td><?= $val->gender == 'M' ? '男':'女'?></td>
                  <td><?= $val->mobileNumber ?></td>
                  <td><?= date('Y-m-d', $val->samplingDate) ?></td>
                  <td>
                    <button class="btn btn-info query_progress">查询进度</button>
                    <button class="btn btn-success check_report">检测报告</button>
                    <?php if (!$val->barcode) {?>
                      <a href="<?= Url::toRoute(['order/create', 'id' => $val->id])?>"><button class="btn btn-info">完善用户</button></a>
                    <?php }?>
                  </td>
                </tr>
                <?php endforeach;?>
                </tbody>
              </table>
            </div>
            <!-- /.box-body -->
            <?= LinkPager::widget(['pagination' => $pages]); ?>
          </div>
          <div class="info_box">
            <div class="zhezhao"></div>
            <div class="infos"></div>
          </div>

          <div class="search_box">
          <div class="zhezhao"></div>
          <div class="search_form">
            <?= Html::beginForm(Url::toRoute('order/datalist'), 'get', ['id' => 'search-form', 'class'=>'form-horizontal']); ?>
              <div class="box-body">
                <div class="form-group">
                  <label for="search_barcode">barcode</label>
                  <?=Html::input('text','barcode','',['class' => 'form-control', 'id' => "search_barcode", 'placeholder' => "请输入条形码"]);?>
                </div>
                <div class="form-group">
                  <label for="search_uname">姓名</label>
                  <?=Html::input('text', 'name','',['class' => 'form-control', 'id' => "search_uname", 'placeholder' => "请输入用户姓名"]);?>
                </div>
                <div class="form-group searchsex_box">
                  <span>性别</span>
                  <div class="radio">
                    <label><?=Html::radioList('sex','1',['M'=>'男','F'=>'女'],['class'=>'form-control']);?></label>
                  </div>
                </div>
                <div class="form-group">
                  <label for="search_phone">电话</label>
                  <?=Html::input('text','mobileNumber','',['class' => 'form-control', 'id' => "search_phone", 'placeholder' => "请输入用户电话"]);?>
                </div>
                <div class="form-group">
                  <label>检测时间</label>

                  <div class="input-group">
                    <div class="input-group-addon">
                      <i class="fa fa-calendar"></i>
                    </div>
                    <?=Html::input('text','check_time', '', ['class' => 'form-control', 'id' => "reservation"]);?>
                  </div>

                </div>
              </div>
              <div class="box-footer">
              <?= Html::submitButton('提交',['class'=>'btn btn-primary']);?>
              <input class="btn btn-warning btn-close" readonly value="关闭" style="width:200px" />
              </div>
            <?= Html::endForm(); ?>
          </div>
        </div>

<script type="text/javascript" src="js/jquery.js"></script>
<!-- date-range-picker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script src="plugins/daterangepicker/daterangepicker.js"></script>
<script>
$(".info_box .zhezhao").click(function(){
  $(this).parent(".info_box").hide();
});
$(".search_box .zhezhao").click(function(){
  $(this).parent(".search_box").hide();
});
$(".btn-close").click(function(){
  $(".search_box").hide();
});
  $(".query_progress").click(function(){
    var barcode = $(this).parent().siblings('.barcode').text();
    var url = "<?= Url::toRoute('order/checkbarcode')?>";
    var _csrf ="<?= Yii::$app->request->getCsrfToken()?>";
    $.ajax({
        type:"GET",
        url:url,
        data:{
          _csrf:_csrf,
          barcode:barcode
        },
        dataType:"json",
        success:function(json){
          if(json.flag==true){
            var msg = '';
            for (x in json.msg) {
              msg +="<li><span class='lf'><strong>结果</strong>: "+json.msg[x].name+"</span><span class='rt'><strong>时间</strong>: "+json.msg[x].time+"</span></li>";
            }
            $(".infos").html(msg); 
            $(".info_box").show();
          }else{
            var content = "检测单号'"+ barcode + "'<br/>当前的状态为: " + json.msg;
            $(".infos").html(content); 
            $(".info_box").show();
          }

        },
        error:function(){
          alert('网络忙');
        }
      });
  });

  $(".check_report").click(function(){
    var barcode = $(this).parent().siblings('.barcode').text();
    var url = "<?= Url::toRoute('order/checkreport')?>";
    var _csrf ="<?= Yii::$app->request->getCsrfToken()?>";
    $.ajax({
        type:"GET",
        url:url,
        data:{
          _csrf:_csrf,
          barcode:barcode
        },
        dataType:"json",
        success:function(json){
            if (json.flag == false) {
              var content = "检测单号'"+ barcode + "'<br/>当前的状态为: " + json.msg;
              $(".infos").html(content); 
              $(".info_box").show();
            } else if (json.flag == true) {
              window.open(json.msg);
            } else {
              alert('网络忙');
            }
        },
        error:function(){
          alert('网络忙');
        }
      });
  });

  $('#reservation').daterangepicker();
    //Date range picker with time picker
    $('#reservationtime').daterangepicker({timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A'});
    //Date range as a button
    $('#daterange-btn').daterangepicker(
        {
          ranges: {
            'Today': [moment(), moment()],
            'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
            'Last 7 Days': [moment().subtract(6, 'days'), moment()],
            'Last 30 Days': [moment().subtract(29, 'days'), moment()],
            'This Month': [moment().startOf('month'), moment().endOf('month')],
            'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
          },
          startDate: moment().subtract(29, 'days'),
          endDate: moment()
        },
        function (start, end) {
          $('#daterange-btn span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        }
    );

    /*搜索按钮*/
    $(".search_btn").click(function(){
      $(".search_box").show();
    });

    /*新增按钮*/
    $(".sign_btn").click(function(){
      window.location.href = "<?= Url::toRoute(['order/create'])?>";
    });
</script>    